﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.NativeInterop;

namespace Game
{
    public class Charr
    {
        public static int _MaxSp = Form1.MaxSp;
        public static int _MaxInv = Form1.MaxInv;
        public static bool _Loaded = false;
        public static int _GameLevel = 0;               // 1-5 (Game Difficulty)
        public static string _CharName;                 // Max 50 Characters
        public static int _Level;                       // Max 20
        public static string _Class;                    // 1-5
        #region Class
                            //.______________________________________.
                            //| Class | Atk | Def | HP | MAtk | MDef |
                            //|--------------------------------------|
                            //| K     | 4   | 5   | 2  | 3    | 1    |
                            //| S     | 2   | 4   | 3  | 1    | 5    |
                            //| A     | 5   | 3   | 1  | 2    | 4    |
                            //| Ma    | 3   | 1   | 4  | 5    | 2    |
                            //| Mo    | 1   | 2   | 5  | 4    | 3    |
                            //.--------------------------------------.
        #endregion
        public static int[] _Spells = new int[4];       // ~15 Skills per class but max of 4 at a time
        public static int _HP;                          // Max 1,000,000
        public static double _Attack;                   // Max 1,000,000
        public static double _MAttack;                  // Max 1,000,000
        public static double _Defence;                  // Max 1,000,000        
        public static double _MDefence;                 // Max 1,000,000  
        public static int _Money;                       // Max 1,000,000              
        public static int[] _Gear = new int[10];        // 10 - Head, Neck, Shoulders, Chest, Hands, 
                                                        // Hand Jewellery, Legs, Feet, Weapon, Offhand.
        public static int[] _Inventory = new int[20];   // 20  
        public static int _LocationX;
        public static int _LocationY;
  
        public static void LoadChar(string FilePath)
        {
            if (_Loaded == false)
            {
                IniFile LoadIni = new IniFile(Application.StartupPath + FilePath);
                #region GameLevel
                string sGameLevel = LoadIni.ReadString("User", "GameLevel", "");
                if (sGameLevel == "Newb")
                {
                    _GameLevel = 1;
                }
                else if (sGameLevel == "Casual")
                {
                    _GameLevel = 2;
                }
                else if (sGameLevel == "Adventure")
                {
                    _GameLevel = 3;
                }
                else if (sGameLevel == "Challenge")
                {
                    _GameLevel = 4;
                }
                else
                {
                    _GameLevel = 5;
                }
                #endregion
                _CharName = LoadIni.ReadString("Character", "Name", "");
                _Level = LoadIni.ReadInt("Character", "Level", 1);
                _Class = LoadIni.ReadString("Character", "Class", "Assassin");
                _HP = LoadIni.ReadInt("Character", "HP", 0);
                _Attack = Convert.ToDouble(LoadIni.ReadInt("Character", "Attack", 0));
                _MAttack = Convert.ToDouble(LoadIni.ReadInt("Character", "MAttack", 0));
                _Defence = Convert.ToDouble(LoadIni.ReadInt("Character", "Defence", 0));
                _MDefence = Convert.ToDouble(LoadIni.ReadInt("Character", "MDefence", 0));
                _Money = LoadIni.ReadInt("Character", "Money", 0);
                #region Spells, Inventory and Gear
                for (int i = 0; i < _MaxSp; i++)
                {
                    _Spells[i] = LoadIni.ReadInt("Spells", "Spell" + i, 0);
                }
                for (int i = 0; i < _MaxInv; i++)
                {
                    _Inventory[i] = LoadIni.ReadInt("Inventory", "Item" + i, 0);
                }
                for (int i = 0; i < 10; i++)
                {
                    _Gear[i] = LoadIni.ReadInt("Equipment", "Equip" + i, 0);
                }
                #endregion
                _LocationX = LoadIni.ReadInt("Character", "LocationX", 1);
                _LocationY = LoadIni.ReadInt("Character", "LocationY", 1);
                _Loaded = true;
            }
        }
    }

}
